#include "wordBreak.h"
bool wordBreak(std::string s, std::vector<std::string> &wordDict) {
    const int n = s.size();
    const std::set<std::string> works =
        std::set<std::string>(wordDict.begin(), wordDict.end());
    std::vector<bool> dp = std::vector<bool>(n + 1);
    dp[0] = true;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < i; j++) {
            if (dp[j] && works.find(s.substr(j, i - j)) != works.end())
                dp[i] = true;
        }
    }
    return dp[n];
}
